#pragma once

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <iostream>


class InetAddr
{
private:
    void ToHost(struct sockaddr_in addr)
    {
        _port = htons(addr.sin_port);    
        _ip = inet_ntoa(addr.sin_addr);
    }

public:
    InetAddr(struct sockaddr_in addr)
        :_addr(addr)
    {
        ToHost(_addr);
    }

    uint16_t Port()
    {
        return _port;
    }

    std::string IP()
    {
        return _ip;
    }

    bool operator==(InetAddr& addr)
    {
        return IP() == addr.IP() && Port() == addr.Port();
    }

    struct sockaddr_in Addr()
    {
        return _addr; 
    }

    std::string AddrString()
    {
        return _ip + ":" + std::to_string(_port);
    }

private:
    struct sockaddr_in _addr;
    uint16_t _port;
    std::string _ip;
};